var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
ctx.fillStyle='#00ff00';
canvas.addEventListener('mousemove', drawLine, false);

function drawLine(e) {
    var x = getMousePos(e)[0] - this.offsetLeft;
    var y = getMousePos(e)[1] - this.offsetTop;

    ctx.beginPath();
    ctx.arc(x,y,1,0,2*Math.PI,false);
    ctx.fill();
};

function getMousePos(e) {
    var x;
    var y;

    if (e.pageX != undefined && e.pageY != undefined) {
        x = e.pageX;
        y = e.pageY;
    } else {
        x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
        y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
    }

    // console.log('x=' + x + ',y=' + y);
    return [x, y];
}